import time

from selenium.webdriver.common.by import By

from common.Uilt import forum_driver

class details:
    driver = ""
    def __init__(self):
        self.driver = forum_driver.driver
        self.driver.get("http://127.0.0.1:58080/sign-in.html")
        self.driver.find_element(By.CSS_SELECTOR, "#username").send_keys("asd")
        self.driver.find_element(By.CSS_SELECTOR, "#password").send_keys("123")
        self.driver.find_element(By.CSS_SELECTOR, "#submit").click()

    #查看帖子日常信息是否正常
    def details_info(self):
        time.sleep(3)
        #self.driver.find_element(By.XPATH,'//*[@id="artical-items-body"]/div[5]/div/div[2]/div[1]/a').click()
        self.driver.find_element(By.XPATH,'//*[@id="artical-items-body"]/div[5]/div/div[2]/div[1]/a').click()

        text1 = self.driver.find_element(By.CSS_SELECTOR,"#details_article_content_title").text
        assert text1 == "test" #说明帖子正常
        forum_driver.getwinshot()

    def details_thumbsUp(self):
        self.driver.find_element(By.CSS_SELECTOR,"#artical-items-body > div:nth-child(8) > div > div.col > div.text-truncate > a > strong").click()
        text2 = self.driver.find_element(By.CSS_SELECTOR,"#details_article_likeCount").text
        assert text2 == "8" #表示点赞成功
        forum_driver.getwinshot()

        #同一用户在同一文章中点赞 判断是否检查
        self.driver.find_element(By.CSS_SELECTOR, "#details_btn_like_count > svg").click()
        text2 = self.driver.find_element(By.CSS_SELECTOR, "#details_article_likeCount").text
        if text2 != "8":  # 表示点赞成功
            print("text2 != 8")
        forum_driver.getwinshot()

    def reply_null_fail(self):
        self.driver.find_element(By.Css_selector, "#details_btn_article_reply > svg").click()
        text3 = self.driver.find_element(By.CSS_selector, "body > div.jq-toast-wrap.bottom-right > div").get_attribute("style")
        assert text3 != "text-align: left; display: none;" #说明回复失败
        forum_driver.getwinshot()

    def reply_Suc(self):
        self.driver.find_element(By.CSS_selector, "#article_details_reply > div.editormd-toolbar > div > ul > li:nth-child(20) > a > i").click()
        self.driver.find_element(By.Css_selector, "#details_btn_article_reply > svg").click()
        text4 = self.driver.find_element(By.CSS_SELECTOR,"body > div.jq-toast-wrap.bottom-right > div").text
        assert text4 != "text-align: left; display: none;" #说明回复成功
        forum_driver.getwinshot()

det = details()
det.details_info()
det.details_thumbsUp()
det.reply_null_fail()
det.reply_Suc()
det.driver.quit()

